package com.spring.comment.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import com.fasterxml.jackson.databind.util.JSONPObject;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mangofactory.swagger.annotations.ApiIgnore;
import com.spring.appservice.web.service.MainShowService;
import com.spring.comment.web.service.CommentService;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.security.web.dao.JedisCache;


@Service
@Controller
@RequestMapping(value = "/comment")
@ApiIgnore
public class CommentController {

	@Resource
	private CommentService commentService;
	
	@Resource
	private MongoTemplate mongoService;
	@Resource
	private MainShowService mainShowService;
	
	@Resource
	private JedisCache jedisCache;

	/**
	 * 获取所有区域信息
	 * 
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/createCommentService")
	@ResponseBody
	public Object createCommentService(String token, String serviceID, String businessTypeCode, String serviceModuleCode, String comment,
			String callback) {

		Map<String, Object> m = new HashMap<String, Object>();
		try {
			
			m = commentService.createCommentService(token, serviceID, businessTypeCode, serviceModuleCode, comment);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	/**
	 * 获取所有区域信息
	 * 
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/createCommentCustomerService")
	@ResponseBody
	public Object createCommentCustomerService(String token, String serviceID,String toUserID,String toUserType,
			String toUserName, String businessTypeCode, String serviceModuleCode, String comment,String callback) {
				
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			
			m = commentService.createCommentCustomerService(token, serviceID, toUserID, toUserType, toUserName, businessTypeCode, serviceModuleCode, comment);

		} catch (Exception e) {
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
			e.printStackTrace();

		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	


	/**
	 * 得到服务评论
	 * @param businessTypeCode
	 * @param serviceID
	 * @param userID
	 * @param serviceModuleCode
	 * @param pageSize
	 * @param pageIndex
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
		@RequestMapping(value = "/getCommentService")
		@ResponseBody
		public Object getCommentService(String businessTypeCode,String serviceID,String userID,
				String serviceModuleCode,String pageSize,String pageIndex,String skip,String rows,String callback) {
					
			Map<String, Object> m = new HashMap<String, Object>();
			try {
				
		//		m = commentService.getCommentService(businessTypeCode, serviceID, userID, serviceModuleCode, pageSize, pageIndex, skip, rows);

			} catch (Exception e) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "系统异常");
				e.printStackTrace();

			}

			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, m);
			} else {
				return m;
			}
		}
		

		/*
		 * 得到评论项目和人
		 */
		@RequestMapping(value = "/getCommentServiceItem")
		@ResponseBody
		public Object getCommentServiceItem(String businessTypeCode,String serviceID,String userID,
				String serviceModuleCode,String pageSize,String pageIndex,String skip,String rows,String callback) {
					
			Map<String, Object> m = new HashMap<String, Object>();
			try {
				
		//		m = commentService.getCommentServiceItem(businessTypeCode, serviceID, userID, serviceModuleCode, pageSize, pageIndex, skip, rows);
						
			} catch (Exception e) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "系统异常");
				e.printStackTrace();

			}

			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, m);
			} else {
				return m;
			}
		}
		
		
		
		
		
		
		/**
		 * 得到评论客户
		 * @param businessTypeCode
		 * @param serviceID
		 * @param toUserID
		 * @param fromUserID
		 * @param serviceModuleCode
		 * @param pageSize
		 * @param pageIndex
		 * @param skip
		 * @param rows
		 * @param callback
		 * @return
		 */
		@RequestMapping(value = "/getCommentCustomer")
		@ResponseBody
		public Object getCommentCustomer(String businessTypeCode,String serviceID,String toUserID,String fromUserID,
				String serviceModuleCode,String pageSize,String pageIndex,String skip,String rows,String callback) {
					
			Map<String, Object> m = new HashMap<String, Object>();
			try {
				
				m = commentService.getCommentCustomer(businessTypeCode, serviceID, toUserID, fromUserID, serviceModuleCode, pageSize, pageIndex, skip, rows);
				
			} catch (Exception e) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "系统异常");
				e.printStackTrace();

			}

			if (ApplicationUtils.isNotNull(callback)) {
				return new JSONPObject(callback, m);
			} else {
				return m;
			}
		}
		
		
		

}
